<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>订单查询-azhuo商城</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta http-equiv="Cache-Control" content="no-siteapp" />

	<link rel="shortcut icon" href="${pageContext.request.contextPath }/image/logo/xyz.ico" type="image/x-icon" />
	<link rel="stylesheet" href="${pageContext.request.contextPath }/css/font.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/css/xadmin.css">

	<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery.min.js"></script>
	<script src="${pageContext.request.contextPath }/lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/js/xadmin.js"></script>
</head>

<body>
	<div class="x-nav">
		<span class="layui-breadcrumb">
			<a href="${pageContext.request.contextPath }/adminjsps/home.jsp" target="iframe_a">首页</a>
			<a><cite>订单管理</cite></a>
		</span>
		<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
			href="javascript:location.replace(location.href);" title="刷新">
			<i class="layui-icon" style="line-height:30px">ဂ</i>
		</a>
	</div>
	<div class="x-body">
		<div class="layui-row">
			<form class="layui-form layui-col-md12 x-so" method="post"
				action="${pageContext.request.contextPath }/admin/AdminOrderServlet">
				<input type="hidden" name="method" value="findOrder" />
				<div class="layui-input-inline">
					<select name="ostate">
						<option value="">订单状态</option>
						<option value="1">待付款</option>
						<option value="2">待发货</option>
						<option value="3">待收货</option>
						<option value="4">已收货</option>
					</select>
				</div>
				<input type="text" name="oid" placeholder="请输入订单号" autocomplete="off" class="layui-input">
				<input type="submit" class="layui-btn" value="搜索" />
				<!-- <button id=""  lay-submit="" lay-filter="sreach">
					<i class="layui-icon">&#xe615;</i>
				</button> -->
			</form>
		</div>

		<xblock style="height: 35px;">
			<span class="x-right" style="line-height:40px">共有数据：${fn:length(orderList) } 条</span>
		</xblock>

		<%-- 订单列表 --%>
		<table class="layui-table">
			<thead>
				<tr style="text-align: center;">
					<th>
						<div class="layui-unselect header layui-form-checkbox" lay-skin="primary">
							<i class="layui-icon">&#xe605;</i>
						</div>
					</th>
					<th>订单编号</th>
					<th>收货人</th>
					<th>总金额</th>
					<th>订单状态</th>
					<th>收货地址</th>
					<th>下单时间</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				<c:forEach items="${orderList }" var="order">
					<tr>
						<td>
							<div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'>
								<i class="layui-icon">&#xe605;</i>
							</div>
						</td>
						<td>${order.oid }</td>
						<td>${order.user.username }</td>
						<td>${order.total }</td>
						<td>
							<c:choose>
								<c:when test="${order.ostate == 1 }">待付款</c:when>
								<c:when test="${order.ostate == 2 }">
									<div style="line-height: 30px;">
										<span>待发货</span><br />
										<a href="${pageContext.request.contextPath }/admin/AdminOrderServlet?method=sendGoods&oid=${order.oid }"
											style="font-size: 12px; color: #aaf;">发货&nbsp;&gt;&gt;</a>
									</div>
								</c:when>
								<c:when test="${order.ostate == 3 }">待收货</c:when>
								<c:when test="${order.ostate == 4 }">已收货</c:when>
							</c:choose>
						</td>
						<td>${order.oaddress }</td>
						<td>
							<fmt:formatDate value="${order.time }" pattern="yyyy年MM月dd日 HH:mm:ss" />
						</td>
						<td class="td-manage">
							<a title="查看" onclick="x_admin_show('订单明细','${pageContext.request.contextPath}/admin/AdminOrderServlet?method=loadOrderItem&oid=${order.oid }')" href="javascript:;">
								<i class="layui-icon">&#xe63c;</i>
							</a>
							<a title="删除" onclick="member_del(this,'${order.oid}')" href="javascript:;">
								<i class="layui-icon">&#xe640;</i>
							</a>
						</td>
					</tr>
				</c:forEach>
			</tbody>
		</table>

	</div>
	<script>
		$(document).ready(function () {

			// 分页查询所有
			//findAll();
		});

		function findAll() {
			console.log("find All");

			$.ajax({
				type: "POST",// 请求的方式默认为get 改为Post
				url: "${pageContext.request.contextPath}/admin/AdminOrderServlet",// 往服务器端请求的地址 写成绝对路径
				data: {
					method: "findAllOrder"
				},// 往服务器端发送的数据
				// 接受服务器端数据函数 回调函数
				success: function (data) {
					// data是服务器返回的数据
					if (data != "") {
						// 解析字符串，进行把分类添加到页面
						addCategoryData(data);
					} else {
						console.log("服务器端异常请稍后再试");
					}
				}
			});
		}

		layui.use('laydate', function () {
			var laydate = layui.laydate;

			//执行一个laydate实例
			laydate.render({
				elem: '#start' //指定元素
			});

			//执行一个laydate实例
			laydate.render({
				elem: '#end' //指定元素
			});
		});


		/*删除*/
		function member_del(obj, id) {
			layer.confirm('确认要删除吗？', function (index) {
				//发异步删除数据
				$.ajax({
					type: "POST",// 请求的方式默认为get 改为Post
					url: "${pageContext.request.contextPath}/admin/AdminOrderServlet",// 往服务器端请求的地址 写成绝对路径
					data: {
						method: "removeOrder",
						oid: id
					},// 往服务器端发送的数据
					// 接受服务器端数据函数 回调函数
					success: function (data) {
						console.log("data = " + data);
						// data是服务器返回的数据
						if (data != "" && data != "null") {

							$(obj).parents("tr").remove();
							layer.msg('已删除!', {
								icon: 1,
								time: 1000
							});

						} else {
							layer.msg('服务器端异常请稍后再试!', {
								icon: 1,
								time: 1000
							});
						}
					}
				});
			});
		}

		function delAll(argument) {

			var data = tableCheck.getData();

			layer.confirm('确认要删除吗？' + data, function (index) {
				//捉到所有被选中的，发异步进行删除
				layer.msg('删除成功', {
					icon: 1
				});
				$(".layui-form-checked").not('.header').parents('tr').remove();
			});
		}
	</script>
</body>

</html>